
const validatePrice = (rule, value, callback) => {
  if (/^\d+\.?\d?\d?$/.test(value))
    callback();
  else
    callback(new Error('请输入数字值'));
};

let page = {
  total: 1,
  startIndex: 0,
  stepNumber: 40,
  currentPage: 1
};


let data={
  countryList:[],
  postageList:[],
}
let status={
  actionModal:{
    isShow:false,
    isLoading:false,
    title:'',
    content:'',
    action:'',
  },
  modifyModal:{
    isShow:false,
    isLoading:true,
    title:'',
    content:'',
  },
  postageId:'',
  postageName:'',
  postageMethod:0,
  postageRules:{
    // firstWeight: [
    //   {required: true,type:"number", message: '请输入正确的首重', trigger: 'blur'},
    // ],
    name: [
      {required: true, message: '运费名称不能为空', trigger: 'blur'}
    ],
    enName: [
      {required: true, message: '运费英文名称不能为空', trigger: 'blur'}
    ],
    method: [
      {required: true, type: 'integer', message: '配送方式不能为空', trigger: 'change'}
    ],
    tieredWeight:[
      {required: true,type: 'number', message: '阶梯重量不能为空', trigger: 'blur'}

    ],
    minTime:[
      {required: true, type: "integer", message: '最短周期不能为空', trigger: 'blur'}
    ],
    maxTime:[
      {required: true,  type: "integer", message: '最长周期不能为空', trigger: 'blur'},
      {
        validator:(rule, value, callback)=>{
          if(value <= params.postage.minTime){
            callback(new Error('最长周期必须大于最短周期！'));
          }else{
            callback();
          }
        },
        trigger: 'blur'
      }
    ],
    note: [
      {required: true, message: '运费描述不能为空', trigger: 'blur'}
    ],
    minWeight: [
      {required: true, type: "integer", message: '最小包裹重量不能为空', trigger: 'blur'}
    ],
  }
};
let params={
  postageName:'',

  postage:{
    id:'',
    name:'',
    enName:"",
    method:'',
    minTime:1,
    maxTime:1,
    note:"",
    innerNote:"",
    minWeight:0,
    postageRules:[]
  },

  selectedCountryIds:[],
  initCommonConfig:[
    {
      firstWeight:0,
      firstFee:0,
      tieredWeight:0,
      tieredFee:0,
      maxWeight:2000
    },
    {
      firstWeight:2000,
      firstFee:0,
      tieredWeight:0,
      tieredFee:0,
      maxWeight:5000
    },
    {
      firstWeight:5000,
      firstFee:0,
      tieredWeight:0,
      tieredFee:0,
      maxWeight:20000
    },
    {
      firstWeight:20000,
      firstFee:0,
      tieredWeight:0,
      tieredFee:0,
      maxWeight:50000
    }
  ],
  initBusinessConfig:[
    {
      firstWeight:0,
      firstFee:0,
      tieredWeight:0,
      tieredFee:0,
      maxWeight:2000
    },
    {
      firstWeight:2000,
      firstFee:0,
      tieredWeight:0,
      tieredFee:0,
      maxWeight:5000
    },
    {
      firstWeight:5000,
      firstFee:0,
      tieredWeight:0,
      tieredFee:0,
      maxWeight:20000
    },
    {
      firstWeight:20000,
      firstFee:0,
      tieredWeight:0,
      tieredFee:0,
      maxWeight:50000
    }
  ]
};
let  tableTitles=function (self) {
  var titles =  [
    {
      title: '运费名称',
      key: 'name',
      width: 300,
      align: 'center'
    },
    {
      title: '英文名称',
      key: 'enName',
      width: 300,
      align: 'center'
    },
    // {
    //   title: '配送方式',
    //   key: 'method',
    //   width: 130,
    //   align: 'center',
    //   render: (h, params) => {
    //     let isPrimary = params.row.method===100;
    //     return (
    //       <div>
    //         <tag color={isPrimary?'green':'magenta'}>{isPrimary?'普通快递':'商业快递'}</tag>
    //       </div>
    //     );
    //   }
    // },
    {
      title: '最短周期',
      key: 'minTime',
      width: 120,
      align: 'center'
    },
    {
      title: '最长周期',
      key: 'maxTime',
      width: 120,
      align: 'center'
    },
    !self.$authority('OTHER-2-200')?null:{
      title: '操作',
      key: 'action',
      align: 'center',
      // width: 200,
      minWidth: 200,
      render: (h, params) => {
        return h('div', [
          self.$authority('OTHER-2-201')? h('Button', {
              props: {type: 'primary', size: 'small', icon: "ios-create",},
              style: {marginRight: '10px',},
              on: {
                click: () => {
                  self.modify(params.row.id)
                }
              }
            }, "编辑"):h('span',''),
          self.$authority('OTHER-2-202')?h('Button', {
              props: {type: 'error', size: 'small', icon: "md-trash",},
              style: {marginRight: '10px', },
              on: {
                click: () => {
                  self.delete(params.row.id, params.row.name);
                }
              }
            }, "删除 "):h('span',''),
          ])
      },
    }
  ]

  return self.$authTableTitles(titles) ;
};



export  default  {
  tPage: page,
  tStatus: status,
  tParam: params,
  tData: data,
  listTableTitles:tableTitles,
};
